/**
 *
 */
package com.topscomm.file;

import com.topscomm.basic.util.Config;
import com.topscomm.pub.util.SecurityUtil;
import org.springframework.boot.autoconfigure.amqp.RabbitProperties;

/**
 * @Description: 本地redis配置
 * @Date: 2022/7/1 16:31
 * @Version: 1.0
 **/
public class LocalRabbitProperties extends RabbitProperties {

	@Override
	public synchronized void setPassword(String password) {
		super.setPassword(decryptString(password));
	}
	@Override
	public void setUsername(String username) {
		super.setUsername(decryptString(username));
	}
	@Override
	public void setHost(String host) {
		super.setHost(decryptString(host));
	}

	private synchronized String decryptString(String encryptedString) {
		String isEncrypt = Config.getInstance().getValue("IsRabbitEncrypt");
		if (isEncrypt.equalsIgnoreCase("true")) {
			String plainString = encryptedString;
			if (plainString != null && plainString.trim().length() > 0) {
				plainString = SecurityUtil.decryptDes(plainString.trim(), "topscommkey");
			}
			return plainString;
		} else {
			return encryptedString;
		}
	}
}
